package com.fyzk.activity;

import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;

import com.fyzk.base.BaseActivity;
import com.fyzk.constants.ConstantsDJ;
import com.tyjc.lottery.R;
import com.fyzk.raceview.BetNum;
import com.fyzk.raceview.RaceShuZiCaiView;
import com.fyzk.utils.IntentParamUtils;
import com.fyzk.view.TopTitleView;

import java.util.ArrayList;
import java.util.List;

public class MoreCodeActivity extends BaseActivity {

	ListView code_list;

	String content, prizeNum;
	int codeFilter;
	
	public  List<List<BetNum>> betNums = new ArrayList<List<BetNum>>();
	public  List<String> wcodes = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_more_code);
		((TopTitleView) findViewById(R.id.topTitle))
				.setOnTitleClickListener(this);
		code_list = (ListView) findViewById(R.id.content_list);
		codeFilter = getIntent().getIntExtra(
				IntentParamUtils.detail_codefilter, 0);
		prizeNum = getIntent().getStringExtra(IntentParamUtils.detail_prizeNum);
		content = getIntent().getStringExtra(IntentParamUtils.detail_content);
		
		wcodes.clear();
		wcodes.addAll(RaceShuZiCaiView.wcodes);
		betNums.clear();
		betNums.addAll(RaceShuZiCaiView.betNums);
		code_list.setAdapter(new ListAdapter());
		
	}

	private class ListAdapter extends BaseAdapter {
		
		
		

		@Override
		public int getCount() {
			return betNums.size();
		}

		@Override
		public List<BetNum> getItem(int position) {
			return betNums.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			View item;
			ViewHolder  holder= null;
			if (null == convertView) {
				holder = new ViewHolder();
				convertView = LayoutInflater.from(MoreCodeActivity.this).inflate(
						R.layout.detail_szc_race_item, null);
				holder.wcode_tv = (TextView) convertView
						.findViewById(R.id.detail_szc_wcode_tv);
				holder.gv = (GridView) convertView.findViewById(R.id.detail_szc_gv);
				holder.num_tv =  (TextView) convertView.findViewById(R.id.detail_szc_num_tv);
				convertView.setTag(holder);
			} else {
				holder =  (ViewHolder) convertView.getTag();
			}
			holder.wcode_tv.setText(ConstantsDJ.wcode(wcodes.get(position)));
			holder.gv.setVisibility(View.GONE);
			List<BetNum> betNs = betNums.get(position);
			String codes = "";
			for (BetNum betNum : betNs) {
				String code = betNum.betNum;
				// int color;
				// SpannableString ss = new SpannableString(codeValue);
				// if(betNum.isPrizeNum){
				// color = Color.RED;
				// }else{
				// color = Color.BLACK;
				// }
				// ss.setSpan(new ForegroundColorSpan(color), 0,
				// codeValue.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
				if (betNum.isPrizeNum) {
					codes += "<font color=\"#ff0000\">" + code + "</font>" + " ";
				} else {
					codes += "<font color=\"#000000\">" + code + "</font>" + " ";
				}
			}

			String htmlStr = "<html><body>" + codes + "</body></html>";
			holder.num_tv.setText(Html.fromHtml(htmlStr));
			return convertView;
		}
	}
	
	
	class ViewHolder{
		
		TextView wcode_tv ;
		GridView gv ;
		TextView num_tv;
		
		
	} 
	

//	private ViewHolder addItemView(Context context,  View convertView,int position) {
//		List<BetNum>  item_data = betNums.get(position);
//		
//		if(convertView == null){
//			convertView  = LayoutInflater.from(context).inflate(
//					R.layout.detail_szc_race_item, null);
//			TextView 
//			GridView 
//
//			TextView num_tv = (TextView) convertView.findViewById(R.id.detail_szc_num_tv);
//			// if(wcodes.size()>(i+1)){
//			wcode_tv.setValue();
//			// }
//
//			// gv.setEnabled(false);
//			// gv.setAdapter(new GridViewAdapter(betNums.get(i)));
//
//			gv.setVisibility(View.GONE);
//			
//		}else{
//			
//		}
//		 
//
//		return convertView;
//	}

	
}
